Xbasic

ROUND Function

Syntax

Rounded_Number as N = ROUND(N number,N decimal_places)

Arguments

number

Numeric

decimal_places

A integer number greater than or equal to zero.

Description

Rounds off a number to a specified number of decimal places.

Discussion

ROUND() returns a Number rounded off to the specified number of Decimal_Places. If you round to zero Decimal_Places, an integer is returned.

Example

round(2.1234,2) -> 2.12
round(SALARY/52,2) -> 490.38, if SALARY contains 25500

Round() and Matching Excel's Behavior

Prior to November 2013, the round() function in client-side calculated fields was using the built-inJavascript Math.round() method to round values. The Javascript Math.round() function rounds negative numbers differently that some people might expect (and differently than Excel does, for example). For example:

Math.round(-4.5,0)  returns -4

However, Excel returns -5. To be consistent with Excel's behavior (which is likely what most users would expect), when the Round() function is used in a client-side calculation, it now uses the Excel convention. Behind the scenes, the round() function in a client-side calculation is actually translated into the built-in $u.n.round() function in the Alpha Anywhere Javascript library. This function now takes these optional flags

  • u - round up

  • d - round down

  • a - away from zero (new)

  • t - toward zero (new)

For example:

$u.n.round(4.25,1)= 4.3
$u.n.round(-4.25,1) = -4.3

$u.n.round(4.25,1,'u') = 4.3
$u.n.round(-4.25,1,'u') = -4.2

$u.n.round(4.25,1,'d') = 4.2
$u.n.round(-4.25,1,'d') = -4.3

$u.n.round(4.25,1,'a') = 4.3
$u.n.round(-4.25,1,'a') = -4.3

$u.n.round(4.25,1,'t') = 4.2
$u.n.round(-4.25,1,'t') = -4.2

See Also